import { Component, OnInit } from '@angular/core';
import { Store } from '@ngxs/store';
import { RouterSelectors } from '../../../store/router';
import { Navigate } from '@ngxs/router-plugin';
import { GoodsService } from '../goods.service';
import { Shop } from '../goods.model';

@Component({
  selector: 'app-details',
  templateUrl: './details.component.html',
  styleUrls: ['./details.component.scss'],
})
export class DetailsComponent implements OnInit {
  details: Shop = {};

  constructor(
    private store: Store,
    private service: GoodsService,
  ) {
  }

  ngOnInit(): void {
    const params = this.store.selectSnapshot(RouterSelectors.params);
    this.service.shopDetails(Number(params.id)).subscribe(r => {
      this.details = r;
    });
  }

  gotoStore(id: any) {
    this.store.dispatch(new Navigate(['/goods/store', id]));
  }

  addCollect(id) {
    console.log('addCollect', id);
  }

  addCart(id) {
    console.log('addCart', id);
  }
}
